<template>
    <div>
        <el-card class="box-card">
      <div>
        <span class="el-icon-goods"></span>
        <span> 品牌管理列表</span>
        <el-button
          style="float: right"
          type="button"
          size="small"
          @click="goAddPage"
          >添加</el-button
        >
      </div>
    </el-card>

    <el-table :data="brandList" border style="width: 100%" >
      <el-table-column align="center" prop="id" label="编号"></el-table-column>
      <el-table-column align="center" prop="name" label="品牌名称" style=" text-align: center;"> </el-table-column>
      <el-table-column align="center" prop="first_letter" label="品牌首字母"> </el-table-column>
      <el-table-column align="center" prop="sort" label="排序"> </el-table-column>
      <el-table-column align="center" label="品牌制造商">
          <template slot-scope="scope">
          <el-switch
            v-model="scope.row.show_type"
            :active-value="1"
            :inactive-value="0"
          >
          </el-switch>
        </template> </el-table-column>
      <el-table-column label="是否显示" align="center">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.show_status"
            :active-value="1"
            :inactive-value="0"
          >
          </el-switch>
        </template>
      </el-table-column>
      <el-table-column label="相关" align="center"> 
          <template slot-scope="scope">
          <div>商品： {{ scope.row.product_comment_count }}</div>
          <div>评价： {{ scope.row.product_count }}</div>
        </template>
      </el-table-column>
      <el-table-column prop="operation" label="操作" align="center">
          <template slot-scope="scope">
            <el-button @click="editFun(scope.row.id)" size="small" style="background: #409eff; color: #fff; width:56px;height: 28px;">编辑</el-button>
            <el-button @click="delFun(scope.row.id)" type="danger" size="small" style="background: #f56c6c; color: #fff; width:56px;height: 28px;">删除</el-button>
          </template>
      </el-table-column>
    </el-table>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="listQuery.pageNum"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="listQuery.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>
    </div>
</template>

<script>
import {brandList,deleteProduct} from "@/api/product"
export default {
    name:"brand",
    data: function () {
    return {
        brandList:[],
         listQuery:{
       pageSize: 5, //一页10条数据
        pageNum: 1, //当前页
        name: "", //商品名称
        id: null, //货号
        param_count: null, //上架状态
        show_type:null, //审核状态
        first_letter:null,
        show_status:null
      },
      total:this.total,//总数量
    };
    },
    watch: {
    //监听级联菜单的选中的数据是否发生变化了
    productCateValue(newV) {
      console.log(newV);
      //找到 数组的1号元素，赋值给 product_category_id
      this.listQuery.product_category_id = newV[1];
    },
  },
     methods: {
    async getbrandList() {
      const res = await brandList(this.listQuery);
      console.log(res);
      this.brandList = res.data;
      this.total = res.total
    },
     //跳转到添加页面
    goAddPage() {
    //   this.$router.push("/pms/brandAdd");
    },
    //修改
    editFun(id) {
      console.log("修改触发了", id);
    },
    //删除
   delFun(id) {
      console.log("删除触发了", id);
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          //调用删除接口
          deleteProduct({ id: id }).then((res) => {
            console.log(res);
            if (res.type == "success") {
              this.$message({
                type: "success",
                message: "删除成功!",
              });
              this.getbrandList();
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    //5.修改每页显示的条数
    handleSizeChange(val) {
      console.log("修改每页显示的条数 触发了", val);
      this.listQuery.pageSize = val;
      this.listQuery.pageNum = 1;
      //重新获取数据
      this.getbrandList();
    },
    //6.修改当前页的页码
    handleCurrentChange(val) {
      console.log("修改当前页的页码 触发了", val);
      this.listQuery.pageNum = val;
      this.getbrandList();
    },
    },
     mounted() {
    this.getbrandList();
  },
}
</script>

<style  scoped>

</style>